# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=plan9port
pkgver=0_git20230913
pkgrel=0
_commit=984c2824e3569479bace65bdaf9e78a2eb36dd58
pkgdesc="Port of many Plan 9 libraries and programs to Unix"
url="https://9fans.github.io/plan9port/"
arch="all"
license="LPL-1.02"
makedepends="linux-headers libucontext-dev libxt-dev libx11-dev
	fontconfig-dev libxext-dev perl"
options="!check" # upstream doesn't have a test suite
subpackages="$pkgname-doc $pkgname-src::noarch"
source="$pkgname-$pkgver-$_commit.tar.gz::https://github.com/9fans/plan9port/archive/$_commit.tar.gz
	no-html-man-pages.patch
	libucontext.patch
	o_largefile.patch
	plan9.sh"
builddir="$srcdir/$pkgname-$_commit"

export CC9="${CC:-gcc}"
# LDFLAGS are ignored otherwise
export CC9FLAGS="$CFLAGS $LDFLAGS"

build() {
	./INSTALL -b
}

package() {
	# Can only pass a single flag to ./INSTALL.
	# For this reason, we set PLAN9_TARGET (-r flag) directly.
	PLAN9_TARGET=/usr/lib/plan9 ./INSTALL -c

	mkdir -p "$pkgdir"/usr/lib/plan9
	cp -a ./* "$pkgdir"/usr/lib/plan9

	mkdir -p "$pkgdir"/usr/share/doc/$pkgname/
	install -m644 CHANGES CONTRIBUTORS README.md \
		"$pkgdir"/usr/share/doc/$pkgname/

	# Remove unneeded / duplicated files
	cd "$pkgdir"/usr/lib/plan9
	rm -f CHANGES CONTRIBUTING.md CONTRIBUTORS INSTALL \
		LICENSE Makefile README.md install.sum install.log

	install -Dm755 "$srcdir"/plan9.sh \
		"$pkgdir"/etc/profile.d/plan9.sh
}

doc() {
	default_doc
	amove usr/lib/plan9/man/man? usr/lib/plan9/man/index.html \
		usr/lib/plan9/man/lookman.index
}

src() {
	pkgdesc="$pkgdesc (source files)"
	amove usr/lib/plan9/src
}

sha512sums="
1671940cb39787436108b36272186828810b6467d08f4f4b6e1c897139a0534fc8bfcb6ae819bda12adaa323b532cdec0d545049cb69b9cf2b7a316b50e96fac  plan9port-0_git20230913-984c2824e3569479bace65bdaf9e78a2eb36dd58.tar.gz
117c450854ebebfb9fc826c11fac5ef3f06185f4c28aee40eb12beeeaf300bd7b6be414d10a1d4a461f3983c721f7de7ca66a45b40aff6a95788fa859daf7da8  no-html-man-pages.patch
15c3427d36cf9dfaa58c301756d3a8c94ea3acc7edbe3d1b484032acad5c401691e159949844ce277d4bf90b3fc8a38ff8e7c92567b2084c697895f609f11008  libucontext.patch
456da6462d8ee0efd4052cefffa18a642c49fea390a99bcc2da74bcf22895844dade3bdc991bb85d4ed558cd0894a44b51bdb1447a352189e9ca9028da2887e7  o_largefile.patch
1862807e8c45280fbd3e7827c253de093deb773d846713e3c46256e77c409b2d69cce44a2fe086d2776ebf5204707f84a3577324800173daa2f3d4fb3eae09f0  plan9.sh
"
